#!/bin/bash

# Auto-DSL 启动脚本

echo "==================================="
echo "    Auto-DSL 启动脚本"
echo "==================================="

# 检查Java环境
if ! command -v java &> /dev/null; then
    echo "错误: 未找到Java环境，请安装Java 17或更高版本"
    exit 1
fi

# 检查Maven环境
if ! command -v mvn &> /dev/null; then
    echo "错误: 未找到Maven环境，请安装Maven 3.6或更高版本"
    exit 1
fi

# 检查配置文件
if [ ! -f "src/main/resources/application.properties" ]; then
    echo "错误: 未找到配置文件 application.properties"
    exit 1
fi

# 设置默认环境变量（如果未设置）
if [ -z "$OPENAI_API_KEY" ]; then
    echo "警告: 未设置 OPENAI_API_KEY 环境变量"
    echo "请设置: export OPENAI_API_KEY='your-api-key'"
fi

if [ -z "$CLAUDE_API_KEY" ]; then
    echo "警告: 未设置 CLAUDE_API_KEY 环境变量"
    echo "请设置: export CLAUDE_API_KEY='your-api-key'"
fi

if [ -z "$QIANWEN_API_KEY" ]; then
    echo "警告: 未设置 QIANWEN_API_KEY 环境变量"
    echo "请设置: export QIANWEN_API_KEY='your-qianwen-api-key'"
fi

echo ""
echo "开始编译项目..."
mvn clean compile

if [ $? -ne 0 ]; then
    echo "错误: 项目编译失败"
    exit 1
fi

echo ""
echo "编译成功，启动应用..."
echo "应用将在 http://localhost:8080 启动"
echo ""
echo "API端点:"
echo "  - 健康检查: GET  /api/dsl/health"
echo "  - 生成DSL:  POST /api/dsl/generate"
echo "  - 支持模型: GET  /api/dsl/models"
echo "  - DSL类型: GET  /api/dsl/types"
echo ""
echo "按 Ctrl+C 停止应用"
echo "==================================="

# 启动应用
mvn spring-boot:run
